<?php
namespace Admin\Controller;
use Think\Controller;
class UserController extends CommonController {
    public function index(){

        // var_dump($_GET);
        if($_GET){

            $start = strtotime($_GET['start']);
            $end = strtotime($_GET['end']);
            $nickname = $_GET['nickname'];

            if(!$start){
                $start = strtotime("1970-01-01");
            }

            if(!$end){
                $end = time();
            }

            // $sql ="select * from user where create_time > {$start} and create_time < $end and nickname like '%$nickname%'";
            // 
            // $users = M()->query($sql);
            // 
            $map['create_time&create_time'] = array(array('GT', $start), array('LT', $end), '_multi' => true);

            // $map['create_time'] = array('gt',$start);
            // $map['create_time'] = array('lt',$end);
            // 
            // 
            $map['nickname'] = array('like','%'.$nickname.'%');

            $count = M('user')->where($map)->count(); 

            $Page       = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(25)
            $show       = $Page->show();// 分页显示输出

            $users = M('user')->where($map)->limit($Page->firstRow.','.$Page->listRows)->select();


            // var_dump(M('user'));

        }else{
           $users = M('user')->select(); 
        }
    	   
        $this->assign('page',$show);
        $this->assign('data',$_GET);
    	$this->assign('users',$users);
        $this->display();
    }

    public function edit()
    {
    	$uid = I('get.uid');

    	$user = M('user')->find($uid);

    	$this->assign('user',$user);
        $this->display();
    

    }

    public function status()
    {
    	$uid = I('post.uid');

    	$user = M('user')->find($uid);

    	if($user['status']==0){

    		M('user')->where(['uid'=>$uid])->save(['status'=>'1']);
    		$this->ajaxReturn(['error'=>0,'info'=>"已停用"]);
    	}else{
    		M('user')->where(['uid'=>$uid])->save(['status'=>'0']);
    		$this->ajaxReturn(['error'=>1,'info'=>"已启用"]);
    	}
    }

    public function delall()
    {
        $uids = I('post.uids');

        $uids = rtrim($uids,',');

        $sql = "delete from user where uid in(".$uids.")";

        var_dump($sql);
    }
}